<%@page import="helpers.UrlHelper"%>
<%@page import="entities.Category"%>
<%@page import="java.util.Map"%>
<%@page import="entities.Answer"%>
<%@page import="entities.Question"%>
<%@page import="java.util.List"%>
<%@page import="entities.AuthorQuestion"%>
<%@page import="entities.Author"%>
<%
Author author = (Author) request.getAttribute("author");
AuthorQuestion authorQuestion = (AuthorQuestion) request.getAttribute("authorQuestion");
Author a = null;
Category c = null;

List<Question> questions = (List<Question>) request.getAttribute("questions");
List<Question> answers = (List<Question>) request.getAttribute("answers");
Map<String, Author> qAuthors = (Map<String, Author>) request.getAttribute("qAuthors");
Map<String, Author> aAuthors = (Map<String, Author>) request.getAttribute("aAuthors");
Map<String, Category> qCategories = (Map<String, Category>) request.getAttribute("qCategories");
Map<String, Category> aCategories = (Map<String, Category>) request.getAttribute("aCategories");

//Set content for seo
String title = "Author " + author.getName();
String description = "all the information about the author " + author.getName();
String url = UrlHelper.getServerUrl(request) + "/a/" + author.getAlias() + "-" + author.getId();
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/layouts/header.jsp">
	<jsp:param name="title" value="<%=title %>" />
    <jsp:param name="description" value="<%=description %>" />
    <jsp:param name="ogtitle" value="<%=title %>" />
    <jsp:param name="ogurl" value="<%=url %>" />
    <jsp:param name="ogdescription" value="<%=description%>" />
</jsp:include>

		<script type="text/javascript" src="/js/author.js"></script>
		
		<div class="mainContent clearafter">
			<div class="leftMainContent">
				<!-- Content Tab -->
				<div class="content">
					<div class="content_in">
						<!-- user profile -->
						<div class="user_profile">
							<div class="author_photo">
								<img src="<%=author.getAvatar() %>" class="agent_photo" width="150" height="150" >
							</div>
							<div class="agent_biodata">
								<h3><%=author.getName() %></h3>
								<p class="listlinks">
									<span class="i_agent_others">
										<a href="#questions">Questions Asked : <b><%=authorQuestion != null ? authorQuestion.getqIds().size() : "0" %></b></a>
									</span>
									<span class="answers_provider">
										<a href="#answers">Answers provided : <b><%=authorQuestion != null ? authorQuestion.getaIds().size() : "0" %></b></a>
									</span>
								</p>
								
								<div class="adv">
									<script type="text/javascript"><!--
									google_ad_client = "ca-pub-2883566427648799";
									/* question 234x60 */
									google_ad_slot = "6539361082";
									google_ad_width = 234;
									google_ad_height = 60;
									//-->
									</script>
									<script type="text/javascript"
									src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
									</script>
								</div>
							</div>
						</div>
						<!-- end user profile -->
						
						<br /><br />
						
						<!-- tabs question -->
						<ul class="user_tabs">
							<li class="active"><a href="#questions">Questions Asked</a></li>
							<li><a href="#answers">Answers Provided</a></li>
						</ul>
						<!-- end tabs question -->
						
						
						<div id="tabs-content">
							<div id="questions">
								<%
								for (Question question : questions) {
									a = qAuthors.get(question.getAuthor());
									c = qCategories.get(question.getCategory());
								%>
								<!-- question_item -->
								<div class="question_item clearafter">
									<span class="total_answers">
										<a href="#"><%=question.getAnswers().size() %></a> Answers
									</span>
									<h3>
										<a href="/q/<%=question.getId() %>" title="<%=question.getTitle()%>"><%=question.getTitle() %></a>	
									</h3>
									<p>
										<% if (a != null) { %>
										<span class="user">
											Asked by: 
											<strong>
												<a href="/a/<%=a.getAlias() %>-<%=a.getId() %>" title="<%=a.getName()%>"><%=a.getName()%></a>
											</strong>
											
										</span>
										<% } %>
										<% if (c != null) { %>
										<span class="pcate">
											<a rel="tag" href="/c/<%=c.getAlias() %>-<%=c.getId()%>"><%=c.getName() %></a><br>
										</span>
										<% } %>
									</p>
								</div>
								<!-- end question_item -->
								<% } %>
							</div>
							
							<div id="answers">
								<%
								for (Question question : answers) {
								%>
								<!-- question_item -->
								<div class="question_item clearafter">
									<span class="total_answers">
										<a href="#"><%=question.getAnswers().size() %></a> Answers
									</span>
									<h3>
										<a href="/q/<%=question.getId() %>/<%=question.getUrl() %>" title="<%=question.getTitle()%>"><%=question.getTitle() %></a>	
									</h3>
									<p>
										<span class="user">
											Asked by: 
											<strong>
												<a href="#" title="John Doe">John Doe</a>
											</strong>
											
										</span>
										<span class="ptags">
											<a rel="tag" href="#">Computer</a><br>
										</span>
										<span class="pcate">
											<a rel="tag" href="#">Other</a><br>
										</span>
									</p>
								</div>
								<!-- end question_item -->
								<% } %>
							</div>
						</div>
					</div>
				</div>
				<!-- End Content tab -->
			</div>
			<jsp:include page="/elements/right.jsp" />
		</div>
<jsp:include page="/layouts/footer.jsp" />